<?php
function sanitize_vars(&$check,$signatures,$redirect_url = '/admin/error/')
{
	$tmp = array();
//print_r($check);	
	foreach ($signatures as $name => $sig)	{
		
		if(empty($check[$name]) && isset($sig['required']) && $sig['required']) 	{
			
			error_log ("ERROR SANITIZE: '".$name."' required!");
			
			if($redirect_url) {
				header("Location: $redirect_url?required=$name");

				return; //exit();
			}
		}
		
		$tmp[$name] = $check[$name];
		
		if(isset($sig['type']))
		{
			settype($tmp[$name],$sig['type']);
		}
		
		if(isset($sig['function']))
		{
			foreach($sig['function'] as $f)
			{	
				$tmp[$name] = $f($tmp[$name]);
			}
		}
		
		
	}
	
	$check = $tmp;
}